<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('站内消息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="saveConfig()">
                <i class="fa fa-check"></i> 保存
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <form id="notify_config_form">
                <table id="bootstrap-table"></table>
            </form>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "back/message/notify/config";

    function saveConfig(){
        var noticeNotifyIdArr = [];
        var emailNotifyIdArr = [];
        var smsNotifyIdArr = [];
        $('input[name="noticeNotifyIdArr[]"]:checked').each(function(){
            noticeNotifyIdArr.push($(this).val());
        });
        $('input[name="emailNotifyIdArr[]"]:checked').each(function(){
            emailNotifyIdArr.push($(this).val());
        });
        $('input[name="smsNotifyIdArr[]"]:checked').each(function(){
            smsNotifyIdArr.push($(this).val());
        });
        $.operate.saveModal(prefix + "/edit", {
            noticeNotifyIds:noticeNotifyIdArr.join(','),
            emailNotifyIds:emailNotifyIdArr.join(','),
            smsNotifyIds:smsNotifyIdArr.join(','),
        });
    }

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "站内消息",
            columns: [
                {
                    field: 'notifyId',
                    title: '通知ID',
                    visible: false
                },
                {
                    field: 'notifyName',
                    title: '通知名称',
                },
                {
                    field: 'isAcceptNotice',
                    title: '<input type="checkbox" name="noticeAll">是否接收站内消息',
                    formatter: function (value, row, index) {
                        var checked = value === 1?"checked":"";
                        return '<input type="checkbox" name="noticeNotifyIdArr[]" value="'+row.notifyId+'" '+checked+'>';
                    }
                },
                {
                    field: 'isAcceptEmail',
                    title: '<input type="checkbox" name="emailAll">是否接收邮件',
                    formatter: function (value, row, index) {
                        var checked = value === 1?"checked":"";
                        return '<input type="checkbox" name="emailNotifyIdArr[]" value="'+row.notifyId+'" '+checked+'>';
                    }
                },
                {
                    field: 'isAcceptSms',
                    title: '<input type="checkbox" name="smsAll">是否接收短信',
                    formatter: function (value, row, index) {
                        var checked = value === 1?"checked":"";
                        return '<input type="checkbox" name="smsNotifyIdArr[]" value="'+row.notifyId+'" '+checked+'>';
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>